﻿#region Using

using System;
using System.Text;
using System.Windows.Forms;
using Onyx;

#endregion

namespace onyxLauncher
{
    public partial class ConsoleWindow : Form, IConsoleWindow
    {
        #region Members

        private bool wasError=false;

        #endregion

        #region Constructor

        public ConsoleWindow()
        {
            InitializeComponent();
            listStatus.Items.Add("Console initialised");
        }

        #endregion

        #region IConsoleWindow Members

        /// <summary>
        /// Output text to the console
        /// </summary>
        /// <param name="text">text to output</param>
        public void print(string text)
        {
            listStatus.Items.Add(text);
        }

        /// <summary>
        /// Output error text to the console.
        /// It will show the console window. 
        /// </summary>
        /// <param name="text">error text to output</param>
        public void error(string text)
        {
            listStatus.Items.Add(text);
            lblError.Text = text;

            ShowDialog();
        }

        /// <summary>
        /// This will kill the current process and all ascociated threads
        /// </summary>
        public void quit()
        {
            Environment.Exit(0);
        }

        #endregion

        #region Events

        private void btnQuit_Click(object sender, EventArgs e)
        {
            if (wasError)
                Close();
            else
                visible(false);
        }

        private void btnCopy_Click(object sender, EventArgs e)
        {
            var buff = new StringBuilder();
            Clipboard.Clear();
            foreach (string s in listStatus.Items)
                buff.Append(s + "/n");
            Clipboard.SetText(buff.ToString());
            Application.DoEvents();
        }

        private void btnClean_Click(object sender, EventArgs e)
        {
            listStatus.Items.Clear();
        }

        #endregion

        /// <summary>
        /// Visibility of the console window
        /// </summary>
        /// <param name="show">IsVisible</param>
        public void visible(bool show)
        {
            Visible = show;
        }

        /// <summary>
        /// Visibility of the splash screen
        /// </summary>
        /// <param name="show">IsVisible</param>
        public void splash(bool show)
        {
            SplashWindow.on(show);
        }
    }
}